<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/> 
  <style type="text/css">
  	.table input{display: nones;}
	#biaozhu{cursor: pointer;}
  </style>
   
  <section class="content">
    <div class="container-fluid">
      <div class="panel panel-default">
        <div class="panel-heading"> 
          <h3 class="panel-title"><i class="fa fa-list"></i>订单/产品溢价列表</h3>
        </div>
        <div class="panel-body">
		<div class="navbar navbar-default">
                <form id="search-form2" class="navbar-form form-inline"  method="get" action="{:U('yijia')}">
                <div class="form-group">
					<div class="form-group">
				   <select name="fenbu_id" id="fenbu_id" class="input-sm" style="width:100px;">
					   <option value="-1">全部区域</option>
				   <foreach name="fenbu_list" item="v">
					   <?php 
					   if(I('fenbu_id')==$v['fenbu_id']){
								echo '<option value="'.$v['fenbu_id'].'" selected>'.$v['fenbu_name'].'</option>';
						   }else{
							    echo '<option value="'.$v['fenbu_id'].'">'.$v['fenbu_name'].'</option>';
						   }
					   ?>
				   </foreach>
				   </select>
				  </div>
                  <div class="input-group">
                    <input type="text" class="form-control" id="order_sn" placeholder="订单号" value="{$Think.request.order_sn}" name="order_sn" />
                  </div>

                  <div class="input-group">
                    <input type="text" class="form-control" id="goods_name" placeholder="产品名" value="{$Think.request.goods_name}" name="goods_name"/>
                  </div>
				<div class="form-group">
				                  <select name="yijia_status" id="yijia_status" class="form-control">
									<?php
										if(I('yijia_status')=='0'){
											echo '<option value="">全状态</option>
											<option value="0" selected="selected">未收款</option>
											<option value="1">已收款</option>';
									}elseif(I('yijia_status')=='1'){
										echo '<option value="">全状态</option>
										<option value="0">未收款</option>
										<option value="1" selected="selected">已收款</option>';
									}else{
										echo '<option value="" selected="selected">全状态</option>
										<option value="0">未收款</option>
										<option value="1">已收款</option>';
									}
									?>
				                  </select>
				                </div>
                   <div class="input-group margin" style="width: 250px;">                    
                   <!-- <div class="input-group-addon">
                        入库时间<i class="fa fa-calendar"></i>
                    </div> -->
                       <input type="text" id="start_time" value="{$timegap}" autocomplete="off" name="timegap" class="form-control pull-right">
                  </div>                  
                </div>
                <div class="form-group">
					<button type="button" style="margin-left: 20px;" class="btn btn-primary pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>

					<button class="btn btn-primary" id="button-filter search-order" type="submit"><i class="fa fa-search"></i> 筛选</button>
                </div>
                </form>
			
          </div>
                        
          <div id="ajax_return"> 
                 
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
								<th class="sorting text-center">订单号</th>
                                <th class="sorting text-center">产品名</th>
								<th class="sorting text-center">商户名</th>
                                <th class="sorting text-center">客户名</th>
								<th class="sorting text-center">单价</th>
								<th class="sorting text-center">数量</th>
								<th class="sorting text-center">原小计</th>
								<th class="sorting text-center">实收小计</th>
								<th class="sorting text-center" style="color:red;">收益小计</th>
								<th class="sorting text-center">状态</th>
                                <th class="sorting text-center">下单时间</th>
                            </tr>
                            </thead>
                            <tbody> 

                            <volist name="list" id="v">
                                <tr>
									<td class="text-center"><a href="javascript:" id="chakan" rel="{$v.order_id}">{$v.order_sn}</a></td>
                                    <td class="text-center">{$v.goods_name}</td>
									<td class="text-center">{:$stores[$v['store_id']]}</td>
									<td class="text-center">{$v.consignee}</td>
									<td class="text-center">{$v.y_price}</td>
									<td class="text-center">{$v.goods_num}</td>
									<td class="text-center">{$v.xj_yprice}</td>
									<td class="text-center">{:$v['xj_yprice']+$v['xj_price']}</td>
									<td class="text-center" style="color:red;">{$v.xj_price}</td>
									<?php
									if($v['yijia_status']==1){
										echo '<td class="text-center" style="color:green;">已收款</td>';
									}else{
										echo '<td class="text-center" style="color:red;">未收款</td>';
									}
									?>
									<td class="text-center">{$v.add_time|date='Y-m-d H:i',###}</td>
                                </tr>
                            </volist>
                            </tbody>
							<tbody>
								<tr style="font-size: 16px;color: red;">
									<td colspan="6" align="right">合计：</td>
									<td align="center">￥{$ys_price}</td>
									<td align="center">￥{$sj_sprice}</td>
									<td align="center">￥{$sy_price}</td>
									<td colspan="4"></td>
								</tr>
							</tbody>
                        </table>
                    </div>
                
                <div class="row">
                    <div class="col-sm-6 text-right">{$show}</div>
                </div>
          </div>
        </div>
      </div>
    </div>
    <!-- /.row --> 
  </section>
  <!-- /.content --> 
</div>
<!-- /.content-wrapper --> 
 <script>
	$(document).ready(function() {
		$('#start_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
		    showWeekNumbers: true,
		    timePicker: true,
		    timePickerIncrement: 1,
		    timePicker12Hour: false,
		    ranges: {
		       '今天': [moment(), moment()],
		       '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
		       '最近7天': [moment().subtract('days', 6), moment()],
		       '最近30天': [moment().subtract('days', 29), moment()],
		       '上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
		    },
		    opens: 'left',
		    buttonClasses: ['btn btn-default'],
		    applyClass: 'btn-small btn-primary',
		    cancelClass: 'btn-small',
		    locale : {
		        applyLabel : '确定',
		        cancelLabel : '取消',
		        fromLabel : '起始时间',
		        toLabel : '结束时间',
		        customRangeLabel : '自定义',
		        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
		        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
		        firstDay : 1
		    }
		});
		$("#daochu").click(function(){
			var order_sn=$("#order_sn").val();
			var goods_name=$("#goods_name").val();
			var yijia_status=$("#yijia_status").val();
			var fenbu_id=$("#fenbu_id").val();
			location.href="/index.php/Admin/Finance/export_yijia?order_sn="+order_sn+"&goods_name="+goods_name+"&yijia_status="+yijia_status+"&fenbu_id="+fenbu_id;
		})
	$(".table #biaozhu").click(function(){
		layer.load();
		var obj=$(this).parent().parent();
		var zhi=$(this).attr('rel');var order_id=obj.find('#chakan').attr('rel');var new_rel='';
		if(zhi=='0'){
			new_rel='1';
			obj.find('#biaozhus').html('');
			$(this).css('color','red');$(this).attr('rel',new_rel);
		}else{
			new_rel='0';
			var xuanzhe=obj.find('#biaozhus').attr('rel');
			obj.find('#biaozhus').html('<input type="checkbox" name="alluser_id[]" title="批量收款" value="'+xuanzhe+'">');
			$(this).css('color','#000');$(this).attr('rel',new_rel);
		}
		$.post('/index.php/Admin/Finance/pda',{biaozhu:'biaozhu',order_id:order_id,tag_price:new_rel},function(res){
			layer.closeAll('loading');
		});
	});
	
	$(".table #queren").click(function(){
		var myid=$(this).attr('rel');
		var store_id=$(this).attr('rev');
		var obj=$(this).parent();
		var than=$(this);
		layer.confirm('确定收款吗？确认收款后会结算给商家。', {
		  btn: ['确定','取消'] //按钮
		}, function(){
			$.post('/index.php/Admin/Finance/pda',{action:'yes',order_id:myid,store_id:store_id},function(res){
				if(res==''){
					layer.msg('收款&结算成功！', {icon:6});
					than.remove();
					obj.html('<a href="javascript:" data-toggle="tooltip" style="pointer-events:none;color:green" class="btn btn-default" id="queren">已经收款 <i class="fa fa-check"></i></a>');
				}else{
					layer.msg('收款失败！对账中，禁止收款！', {icon:5});
				}
			});
			
		});
	});
		$("#daochu").click(function(){
			var order_sn=$("#order_sn").val();
			var goods_name=$("#goods_name").val();
			var yijia_status=$("#yijia_status").val();
			var fenbu_id=$("#fenbu_id").val();
			location.href="/index.php/Admin/Finance/export_yijia?order_sn="+order_sn+"&goods_name="+goods_name+"&yijia_status="+yijia_status+"&fenbu_id="+fenbu_id;
		})
$(".table-responsive #chakan").click(function(){
		var myrel=$(this).attr('rel');
		var myrul='/index.php/Admin/order/detail/order_id/'+myrel;//+myrel;
			layer.open({
			  type: 2,
			  title:'订单信息',
			  shadeClose: true, //点击遮罩关闭
			  skin: 'layui-layer-rim', //加上边框
			  area: ['920px', '620px'], //宽高
			  content: myrul
		})
    });
});

    function get_select_order_id_str() {
        if ($('input[name="alluser_id\[\]"]:checked').length == 0)
            return false;
        var goods_arr = Array();
        $('input[name="alluser_id\[\]"]:checked').each(function () {
            goods_arr.push($(this).val());
        });
        var order_id_str = goods_arr.join(',');
        return order_id_str
    }
	
    //批量操作提交
    function act_submit() {
        //prompt层
        var ids = get_select_order_id_str();
        if (ids == false) {
            layer.alert('请勾选要操作的订单', {icon: 2});
            return;
        }
console.log(ids);
		layer.confirm('确定收款吗？确认收款后会结算给商家。', {
		  btn: ['确定','取消'] //按钮 
		}, function(){
			$.post('/index.php/Admin/Finance/pda_piliang',{action:'yes',datas:ids},function(res){
				if(res!=''){
					res=res.slice(0,res.length-1);
					res=res.split(',');
					for(var i=0;i<res.length;i++){
						$('.table-bordered #tr_'+res[i]).html('<a href="javascript:" data-toggle="tooltip" style="pointer-events:none;color:green" class="btn btn-default" id="queren">已经收款 <i class="fa fa-check"></i></a>');
					}
					layer.msg('收款&结算成功！', {icon:6},function(){
						//location.reload();
					});
				}else{
					layer.msg('收款失败！对账中，禁止收款！', {icon:5});
				}
			});
			
		});
    }
</script>
</body>
</html>